$import("com.joypard.platform.organization.org.OrgDI");
$import("com.joypard.platform.security.role.RoleField");

/**
 * 用户
 */
K.defDI("com.joypard.platform.account.user.UserDI", {
	statics : {
		// 字段定义
		fields : [ "userName", "pyUserName", "orgRoleUsers", "posts", "deleted", "account", "sex", "email", "mobile", "enable", "userCode", "orgs",
				"password", "userNickName", "creatorCode", "createTime", "creator", "updater", "updaterCode", "updateTime", "id" ],

		// 访问地址定义
		urls : {
			getUsersByOrgCode : $path + "/account/user/getUsersByOrgCode.do",
			getUsersByOrgId : $path + "/account/user/getUsersByOrgId.do",
			getUsers : $path + "/account/user/getUsers.do",
			userView : $path + "/account/user/userView.do",
			updateUser : $path + "/account/user/updateUser.do",
			addUser : $path + "/account/user/addUser.do",
			delUser : $path + "/account/user/delUser.do",
			getUserRoles : $path + "/account/user/userRoles/getUserRoles.do"
		},

		/**
		 * 创建一个按组织id获取用户的数据存储器
		 */
		createUsersByOrgCodeStore : function(config) {
			var options = {
				url : OrgDI.urls.getOrgUsers,
				fields : this.fields,
				root : "parameters.users"
			};
			if (config) {
				options.baseParams = K.extend(options.baseParams, config.baseParams);
			}
			K.extend(options, config);
			return new K.Ext.data.JsonStore(options);
		},

		/**
		 * 创建用户列表数据源
		 */
		createGetUsersStore : function() {
			var options = {
				url : this.urls.getUsers,
				fields : this.fields,
				root : "parameters.users"
			};
			return new K.Ext.data.JsonListStore(options);
		},

		/**
		 * 创建用户角色数据源
		 * 
		 * @returns {K.Ext.data.JsonStore}
		 */
		createGetUserRolesStore : function() {
			var options = {
				convertRef : true,
				url : this.urls.getUserRoles,
				fields : RoleField.fields,
				root : "parameters.roles"
			};
			return new K.Ext.data.JsonStore(options);
		}
	}
});